<?php

namespace Api\Model;

use Think\Model;

class ReplyModel extends Model {

    function addComment($post_id, $icon, $user_id) {
        $data = array(
            'post_id' => $post_id,
            'user_id' => $user_id,
            'icon' => $icon,
            'createtime' => date('Y-m-d H:i:s')
        );
        return $this->add($data);
    }

    function getCommentbyIds($post_id, $user_id) {
        $where = array(
            'post_id' => $post_id,
            'user_id' => $user_id
        );
        return $this->where($where)->find();
    }

    function addIcons($post_id, $icons) {
        $data['post_id'] = $post_id;
        foreach ($icons as $key => $value) {
            $data[$key] = $value;
        }
        return M('Icons')->add($data);
    }

    function upIcons($post_id, $icons) {
        $where = array('post_id' => $post_id);
        return M('Icons')->where($where)->save($icons);
    }

    function getIcons($post_id) {
        $where = array('post_id' => $post_id);
        return M('Icons')->where($where)->find();
    }

    function getList($post_id, $iCid, $start = 0, $limit = 40) {
        $where = array(
            'jl_reply.post_id' => $post_id,
            'jl_classmember.class_id'=>$iCid
        );
        $join = array('LEFT JOIN __CLASSMEMBER__ on __REPLY__.user_id =__CLASSMEMBER__.user_id');
        $field = 'jl_classmember.rename as name,jl_classmember.user_id as uid,jl_reply.icon as icon,jl_reply.createtime as time';
        $limit = $start . ',' . $limit;
        return $this->where($where)->field($field)->join($join)->limit($limit)->select();
    }

}
